package tech.aistar.Conteoller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import tech.aistar.model.dto.Code;
import tech.aistar.model.dto.Result;
import tech.aistar.util.ImageUtils;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class ImageController {

    @Autowired
    private ImageUtils imageUtils;

    @PostMapping("/image/upload")
    public Result uploadImage(@RequestParam(value = "file",required = false) MultipartFile[] multipartFile){
        if(ObjectUtils.isEmpty(multipartFile)){
            return new Result(Code.BAD, "请选择图片");
        }
        Map<String, List<String>> uploadImagesUrl = imageUtils.uploadImages(multipartFile);
        System.out.println(uploadImagesUrl);
        return new Result(Code.OK, "上传成功",uploadImagesUrl);
    }

}
